package cn.yeyiu.sexyiu.controller

import cn.yeyiu.sexyiu.bean.MangaInfo
import cn.yeyiu.sexyiu.bean.VideoInfo
import cn.yeyiu.sexyiu.data.VideoConfig
import cn.yeyiu.sexyiu.service.VideoService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/sexyiu")
class SexyiuController {
    @Autowired
    lateinit var videoService: VideoService

    @GetMapping("/types")
    fun getTypes(): Array<String>{
        return VideoConfig.VIDEO_TYPES
    }

    // ----------------------------------
    //              anime
    // ----------------------------------
    @GetMapping("/anime/years")
    fun getYears(): Array<String>{
        return VideoConfig.ANIME_YEARS
    }

    @GetMapping("/anime/serial/{year}")
    fun getSerial(@PathVariable("year") year: String): List<String> {
        return videoService.getAnimeSerialByYear(year)
    }

    @GetMapping("/anime/list/{serial}")
    fun getAnimes(@PathVariable("serial") serial: String): List<VideoInfo> {
        return videoService.getAnimeListBySerial(serial)
    }

    @GetMapping("/anime/search/{key}")
    fun searchAnimes(@PathVariable("key") key: String): List<VideoInfo> {
        return videoService.searchAnimes(key)
    }

    @GetMapping("/anime/random")
    fun randomAnime(): VideoInfo {
        return videoService.randomAnime()
    }

    // ----------------------------------
    //              manga
    // ----------------------------------
    @GetMapping("/manga/list")
    fun getMangas(): List<MangaInfo>{
        return videoService.getMangaList()
    }

    @GetMapping("/manga/search/{key}")
    fun searchMangas(@PathVariable("key") key: String): List<MangaInfo> {
        return videoService.getKeyMangas(key)
    }

    @GetMapping("/manga/random")
    fun randomManga(): MangaInfo {
        return videoService.randomManga()
    }

    // ----------------------------------
    //              other
    // ----------------------------------
    @GetMapping("/{type}/list")
    fun getVideos(@PathVariable("type") type: String): List<VideoInfo> {
        return videoService.getOtherVideoList(type)
    }

    @GetMapping("/{type}/search/{key}")
    fun searchVideos(@PathVariable("type") type: String, @PathVariable("key") key: String): List<VideoInfo> {
        return videoService.getKeyVideos(key, type)
    }

    @GetMapping("/{type}/random")
    fun randomVideo(@PathVariable("type") type: String): VideoInfo {
        return videoService.randomVideo(type)
    }
}